package org.fixies.spreadsheet.text.org;

import org.fixies.spreadsheet.AbstractBookLoader;
import org.fixies.spreadsheet.Book;
import org.fixies.spreadsheet.interpreter.BookContext;
import org.fixies.spreadsheet.interpreter.BookNode;
import org.fixies.utils.UnexpectedProblemException;

public class OrgBookLoader extends AbstractBookLoader {


    public OrgBookLoader(Class<?> clazz, BookContext bookContext) {
        super(clazz, bookContext);
    }

    public OrgBookLoader(Class<?> clazz, String fName, BookContext bookContext) {
        super(clazz, fName, bookContext);
    }


    @Override
    protected Book loadBook(String path) {
        BookContext bookContext = getBookContext();
        BookNode bookNode = new BookNode(path);
        bookNode.evaluate(bookContext);
        try {
            Book book = bookNode.getResult();
            return book;
        } catch (RuntimeException e) {
            throw new UnexpectedProblemException(e, "loadBook failed. path=[", path, "]");
        }
    }

}
